{include file="header"}
<div style="padding: 20px;" class="adminmyucms">
<form class="layui-form" action="">
  <div class="layui-form-item" >
     <span style="float: left;line-height: 38px;margin: 0 20px;">分类</span>
      <div style="width: 150px;float: left;">
       <select name="tid" lay-verify="required">
        <option value="0">顶级分类</option>
        {foreach name=":fun_S('cateAdmin',array('tid'=>0),'px desc','1000',1)" item="v" key="k"}
        <option value="{$v.id}">{$v.name}</option>
        <!--
        {volist name=":fun_S('cateAdmin',array('tid'=>$v['id']),'px desc','1000',1)" id="vo"}
        <option value="{$vo.id}" disabled="">——{$vo.name}</option>
        {/volist}
        -->
        {/foreach}
       </select>
      </div>
      <span style="float: left;line-height: 38px;margin: 0 20px;">名称</span>
	  <input type="text" name="name" value=""  placeholder="导航名称" autocomplete="off" lay-verify="required" class="layui-input" style="width: 150px;float: left;">
      <span style="float: left;line-height: 38px;margin: 0 20px;">链接</span>
	  <input type="text" name="lianjie" value=""  placeholder="导航链接" autocomplete="off" lay-verify="required" class="layui-input" style="width: 300px;float: left;">
      <span style="float: left;line-height: 38px;margin: 0 20px;">排序</span>
	  <input type="number" name="px" value="1"  placeholder="排序" autocomplete="off" lay-verify="required" class="layui-input" style="width: 50px;float: left;">
    <button style="float: left;line-height: 38px;margin: 0 20px;" class="layui-btn layui-btn-warm" lay-submit lay-filter="set-add">添加导航</button>
    </div>
</form>
 
{foreach name=":fun_S('cateAdmin',array('tid'=>0),'px desc','1000',1)" item="v" key="k"}
<form class="layui-form" action="">
<input type="hidden" name="id" value="{$v.id}">	
<table class="layui-table" style="width: 1200px;">
  <colgroup>
  	<col width="100">
    <col width="200">
    <col width="450">
    <col width="150">
    <col width="150">
    <col width="100">
    <col width="150">
    <col width="100">
    <col>
  </colgroup>
  <tbody>
    <tr>
      <td style="font-weight:bold;">顶级</td>
      <td><input type="text" name="name" value="{$v.name|htmlspecialchars}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td><input type="text" name="lianjie" value="{$v.lianjie|htmlspecialchars}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td><input type="text" name="ico" value="{$v.ico|htmlspecialchars}" placeholder="图标" autocomplete="off" class="layui-input"></td>
      <td>
        <select name="open" lay-verify="required">
        <option value="1" {if condition="$v['open'] eq '1'"}selected="selected"{/if} >显示</option>
        <option value="0" {if condition="$v['open'] eq '0'"}selected="selected"{/if} >隐藏</option>
        </select>
      </td>
      <td><input type="number" name="px" value="{$v.px}" placeholder="请输入英文字符组成" autocomplete="off" lay-verify="required" class="layui-input" style="float: left;"></td>
      <td><button class="layui-btn layui-btn-normal" style="float: left;" lay-submit lay-filter="set"><i class="layui-icon">&#xe9aa;</i> 更新</button></td>
      <td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit lay-filter="set-delete"><i class="layui-icon">&#xe640;</i> 删除</button></td>
    </tr>
  </tbody>
</table>
</form>
 {volist name=":fun_S('cateAdmin',array('tid'=>$v['id']),'px desc','1000',1)" id="vo"}
<form class="layui-form" action="">
<input type="hidden" name="id" value="{$vo.id}">	
<table class="layui-table" style="width: 1200px;">
  <colgroup>
  	<col width="100">
    <col width="200">
    <col width="450">
    <col width="150">
    <col width="150">
    <col width="100">
    <col width="150">
    <col width="100">
    <col>
  </colgroup>
  <tbody>
    <tr>
      <td style="color: #2196f3;"><i class="layui-icon layui-icon-triangle-r"></i>  二级</td>
      <td><input type="text" name="name" value="{$vo.name|htmlspecialchars}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td><input type="text" name="lianjie" value="{$vo.lianjie|htmlspecialchars}" placeholder="请输入内容" autocomplete="off" class="layui-input"></td>
      <td><input type="text" name="ico" value="{$vo.ico|htmlspecialchars}" placeholder="图标" autocomplete="off" class="layui-input"></td>
      <td>
        <select name="open" lay-verify="required">
        <option value="1" {if condition="$vo['open'] eq '1'"}selected="selected"{/if} >显示</option>
        <option value="0" {if condition="$vo['open'] eq '0'"}selected="selected"{/if} >隐藏</option>
        </select>
      </td>
      <td><input type="number" name="px" value="{$vo.px}" placeholder="请输入英文字符组成" autocomplete="off" lay-verify="required" class="layui-input" style="float: left;"></td>
      <td><button class="layui-btn layui-btn-normal" style="float: left;" lay-submit lay-filter="set"><i class="layui-icon">&#xe9aa;</i> 更新</button></td>
      <td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit lay-filter="set-delete"><i class="layui-icon">&#xe640;</i> 删除</button></td>
    </tr>
  </tbody>
</table>
</form>
{/volist} 
{/foreach}
<script>
layui.use('form',function(){
  var form = layui.form
  ,jq = layui.jquery;

  //更新
  form.on('submit(set)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('{:url("set/cateupdate")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          //location.href = '{:url("index/index")}';
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
  //删除
  form.on('submit(set-delete)', function(data){
    var param = data.field;
        layer.confirm('确定删除? 删除前请慎重', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
    jq.post('{:url("set/catedelete")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
   }); 
    return false;
  });
  //添加
  form.on('submit(set-add)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var param = data.field;
    jq.post('{:url("set/cateinsert")}',param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
          location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
})
</script>
</div>  
{include file="footer"}